package panda.rmi.server.impl;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import panda.query.scan.Scanner;
import panda.query.tree.QueryTreeNode;
import panda.record.Schema;
import panda.rmi.server.ServerMetaData;
import panda.rmi.server.ServerResultSet;

public class PandaServerResultSet extends UnicastRemoteObject implements ServerResultSet {
	Scanner s;
	Schema sch;
	PandaServerConnection conn;

	protected PandaServerResultSet(QueryTreeNode n, PandaServerConnection conn) throws RemoteException {
		super();
		this.s = n.open();
		this.sch = n.getSchema();
		this.conn = conn;
	}

	@Override
	public int getInt(String attr) throws RemoteException {
		// TODO Auto-generated method stub
		return s.getValue(sch.getAttributeByName(attr)).getIntValue();
	}

	@Override
	public ServerMetaData getMetaData() throws RemoteException {
		// TODO Auto-generated method stub
		return new PandaServerMetaData(sch);
	}

	@Override
	public boolean next() throws RemoteException {
		return s.next();
	}

	@Override
	public String getString(String attr) throws RemoteException {
		// TODO Auto-generated method stub
		return s.getValue(sch.getAttributeByName(attr)).getStringValue();
	}

}
